package cn.edu.njust.control;


import cn.edu.njust.service.UserService;
import cn.edu.njust.service.impl.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;


@WebServlet("/root/*")
public class RootController extends BaseServlet {
    UserService us = new UserServiceImpl();

    /**
     * 清除缓存
     *
     * @param request
     * @param response
     * @throws ServletException
     * @throws IOException
     */
    public void clearCache(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        us.clear();//调用方法

        System.out.println("123");

        //响应成功的标识
        response.getWriter().write("success");

//        response.sendRedirect("clearCache.html");
    }

    /**
     *  删除用户
     * @param request
     * @param response
     * @throws ServletException
     * @throws IOException
     */
    public void deleteById(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        String idNo = request.getParameter("id");

        System.out.println(idNo);
        us.deleteById(idNo);    //调用方法


        //响应成功的标识
        response.getWriter().write("success");
    }

    /**
     *  重置密码
     * @param request
     * @param response
     * @throws ServletException
     * @throws IOException
     */
    public void resetById(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        String idNo = request.getParameter("id");

        System.out.println(idNo);
        us.resetById(idNo);    //调用方法


        //响应成功的标识
        response.getWriter().write("success");
    }
}
